package com.example.app.pages.main.home.addNew.addRecord.MyModalBottomSheetRelationPicker

import androidx.compose.foundation.layout.width
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.app.addNewViewModel
import com.example.app.components.MyChip.MyChip
import com.example.app.components.MySpacer.MySpacer
import com.example.app.components.MyText.MyText
import com.example.app.pages.main.home.me.viewModel.AddNewViewModel
import com.example.app.viewmodel.MainViewModel
import kotlinx.coroutines.launch

var myModalBottomSheetRelationPickerState = MyModalBottomSheetRelationPickerState()
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun IncomeToolListRelationPicker(

) {
    var scope = rememberCoroutineScope()
    var accountRelationPeopleList = addNewViewModel.accountRelationPeopleList.collectAsState()
    var selected = myModalBottomSheetRelationPickerState.selected.collectAsState()

    if (accountRelationPeopleList.value == null) {
        scope.launch {
            addNewViewModel.updateAccountRelationPeopleList()
        }
    }
    MyModalBottomSheetRelationPicker(

        onConfirm = {},

    )
    MySpacer(modifier = Modifier.width(12.dp))
    MyChip(onClick = {
        myModalBottomSheetRelationPickerState.flowUpdate_visible(true)
    }) {
        MyText(text = if (selected.value == null) "关系人" else selected.value?.Title.toString())
    }
}